package com.zfl.thread.day04;

public class LockSupport {
    public static Thread t1, t2;
    public static volatile boolean flag = true;

    public static void main(String[] args) {
        t1 = new Thread(() -> {
            for (int i = 1; i <= 51; i+=2) {
                while (!flag) {
//                    System.out.println("t1 park");
                    java.util.concurrent.locks.LockSupport.park();
                }
//                System.out.println("t1 unpark");
                System.out.print(i);
                System.out.print(i + 1);
                flag = !flag;
                java.util.concurrent.locks.LockSupport.unpark(t2);
            }
        });
        t1.start();
        t2 = new Thread(() -> {
            for (int i = 0; i < 26; i++) {
                while (flag) {
//                    System.out.println("t2 park");
                    java.util.concurrent.locks.LockSupport.park();
                }
//                System.out.println("t2 unpark");
                flag = !flag;
                System.out.print((char)('A'+i));
                java.util.concurrent.locks.LockSupport.unpark(t1);
            }
        });
        t2.start();
    }
}
